package com.kunbo.cn.controller.core.purchase;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.kunbo.cn.entity.core.purchase.PurchaseOrderQuantityAdjust;
import com.kunbo.cn.service.core.purchase.PurchaseOrderQuantityAdjustService;
import com.kunbo.cn.util.retu.BuildBean;
import com.kunbo.cn.util.retu.BuildBean1;
import com.kunbo.cn.util.retu.CommonResult;
import com.kunbo.cn.util.retu.Pages;
import com.kunbo.cn.util.retu.ResultBean;
import com.kunbo.cn.util.retu.ResultBean1;
/**
 *
 * @author bjl  
 * @date 2019年4月18日 
 */
@RestController  
@RequestMapping("/PurchaseOrderQuantityAdjust")  
public class PurchaseOrderQuantityAdjustController {
	@Autowired
    private JdbcTemplate jdbcTemplate;
	@Autowired
	private PurchaseOrderQuantityAdjustService service;
	/**
	 * 新增采购调量记录
	 * 
	 */
	@PostMapping("/save")
	public CommonResult add(PurchaseOrderQuantityAdjust poqa) {
		service.save(poqa);
		return new CommonResult(true,"操作成功",null);
	}
	/**
	 * 获取采购调量历史list
	 * @param code
	 * @param materialType
	 * @param page
	 * @param pageSize
	 * @return
	 */
	@PostMapping("/list")
	public ResultBean<List<Map<String,Object>>> list(
			@RequestParam("purchase_order_code")String order_code
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "error", service.list(order_code));//id
	
}
	/**
	 * 获取采购订单
	 * @param page
	 * @param pageSize
	 * @return
	 */
	/*@PostMapping("/OrderList")
	public ResultBean1<List<Map<String,Object>>> OrderList(
			@RequestParam("page")Integer page,
			@RequestParam("pageSize")Integer pageSize
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		ResultBean1<List<Map<String,Object>>> result1 = new ResultBean1<List<Map<String,Object>>>();
		ResultBean<List<Map<String,Object>>>njks=BuildBean.buildResult(result, "success", "error", service.OrderList());//id
		int total=njks.getData().size();
		return BuildBean1.buildResult(result1, "success", "error",total,service.OrderList());//id
}*/
	/**
	 * 获取采购订单
	 * @param page
	 * @param pageSize
	 * @return
	 */
	@PostMapping("/OrderList")
	public ResultBean1<Pages> OrderList(
			@RequestParam("page")Integer page,
			@RequestParam("pageSize")Integer pageSize
			){
		ResultBean1<Pages> result = new ResultBean1<Pages>();
		return BuildBean1.buildResulttoPages(result, "success", "error",service.OrderList1(page,pageSize));//id
}
	/**
	 *订单量调整
	 * 
	 */
  @PostMapping("/AdjustOrderNum")//Adjust
   public int AdjustOrderNum(HttpServletRequest request,HttpServletResponse response) throws SQLException{
	   String purchase_order_code  = request.getParameter("purchase_order_code"); //订单编号
	   String number_of_contracts = request.getParameter("number_of_contracts");//合同总量
	   String actual_quantity=request.getParameter("actual_quantity");//实际下量
	   String adjust_amount=request.getParameter("adjust_amount");//调整量
	   String allowance=request.getParameter("allowance");//待派量
	   return service.AdjustOrderNum(purchase_order_code,number_of_contracts,actual_quantity,adjust_amount, allowance);
  }
}
